﻿using Azure;

namespace WXWorkSvc.Common.TagHelpers;

[HtmlTargetElement("th", Attributes = "asp-for")]
public class THTagHelper : TagHelper
{
    [HtmlAttributeName("asp-for")]
    public ModelExpression For { get; set; } = default!;

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        if (For is null)
            return;
        output.TagMode = TagMode.StartTagAndEndTag;
        //var tagTH = new TagBuilder("th");
        //tagTH.InnerHtml.SetContent();
        ////tag.InnerHtml.AppendHtml(metadata.GetDisplayName());
        if (!string.IsNullOrEmpty(For.Metadata.Description))
        {
            output.Attributes.Add("data-bs-title", For.Metadata.Description);
            output.Attributes.Add("data-bs-toggle", "tooltip");
            output.Attributes.Add("data-bs-placement", "top");
        }

        output.Content.SetHtmlContent(For.GetDisplayName());
    }
}
